package com.mingtu.guards.adapter;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.common.utils.ConvertLatlng;
import com.mingtu.guards.R;
import com.mingtu.guards.bean.IndexFireBean;

import java.util.List;

public class FireNoticeAdapter extends BaseQuickAdapter<IndexFireBean.PageBean.ListBean, BaseViewHolder> {

    private Context context;

    public FireNoticeAdapter(Context context) {
        super(R.layout.item_fire_notice);
        this.context = context;
    }
    @Override
    protected void convert(@NonNull BaseViewHolder helper, IndexFireBean.PageBean.ListBean listBean) {
        String cameraName = listBean.getUserName();
        String createTime = listBean.getCreateTime();
        String address = listBean.getAddress();
        String uploadType = listBean.getUploadType();
        String lnglat = listBean.getLnglat();
        List<IndexFireBean.PageBean.ListBean.FireInfoAttachEntityListBean> entityListBeans = listBean.getFireInfoAttachEntityList();

        if (!StringUtils.isEmpty(cameraName)) {
            helper.setText(R.id.tv_camera_name,cameraName);
        }

        if (!StringUtils.isEmpty(createTime)) {
            helper.setText(R.id.tv_time,createTime);
        }

        if (!StringUtils.isEmpty(address)) {
            helper.setText(R.id.tv_address,address);
        }

        if (!StringUtils.isEmpty(uploadType)) {
            helper.setText(R.id.tv_type,uploadType);
        }

        if (!StringUtils.isEmpty(lnglat)) {
            if (lnglat.indexOf(",") != -1) {
                String[] lnglatArray = lnglat.split(",");
                String lngStr = lnglatArray[0];
                String latStr = lnglatArray[1];
                double lat = Double.parseDouble(latStr);
                double lng = Double.parseDouble(lngStr);
                String myLng = ConvertLatlng.getInstance().convertToSexagesimal(lng);
                String myLat = ConvertLatlng.getInstance().convertToSexagesimal(lat);
                helper.setText(R.id.tv_lng_lat,myLng + "," + myLat);
            }
        }
        if (entityListBeans != null && entityListBeans.size() > 0) {
            IndexFireBean.PageBean.ListBean.FireInfoAttachEntityListBean entityListBean = entityListBeans.get(0); //取第一张照片
            String url = entityListBean.getUrl();
            Glide.with(context)
                    .load(url)
                    .apply(BaseApplication.getRequestOptions())
                    .into((ImageView) helper.getView(R.id.iv_img));
        }
    }
}
